package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.view.View;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemPackerFirstContentBinding;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.utils.NumberConstant;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 *
 * @author younghow
 * @date 2020/8/19
 * description:顶部标题下面的金刚区，这里其实应该是有三种不同的数据类型，但是这个地方只是一个展示功能，所以我们做了一些
 * 处理，来转换成当前的这个类所使用到的对象
 */
public class PackersFirstContentAdapter extends BaseRecycleAdapter<AddressEntity> {

    public PackersFirstContentAdapter(Context context, List<AddressEntity> data) {
        super(context, R.layout.item_packer_first_content, data);
    }

    @Override
    public void convert(ItemViewHolder holder, AddressEntity entity) {
        ItemPackerFirstContentBinding binding = (ItemPackerFirstContentBinding) holder.getmBinding();
        if (entity.getName().length()<= NumberConstant.NUMBER_TWO){
            binding.tvPackerFirstContentName.setText(entity.getName());
        }else if (entity.getName().length()>NumberConstant.NUMBER_TWO && entity.getName().length()<=NumberConstant.NUMBER_FOUR){
            String name = entity.getName().substring(0,2) + "\n" + entity.getName().substring(2);
            binding.tvPackerFirstContentName.setText(name);
        }else {
            String name = entity.getName().substring(0,2) + "\n" + entity.getName().substring(2,4);
            binding.tvPackerFirstContentName.setText(name);
        }

        if (holder.getIndex_position() == datas.size()-1){
            binding.ivPackerFirstContentEnd.setVisibility(View.VISIBLE);
        }else {
            binding.ivPackerFirstContentEnd.setVisibility(View.GONE);
        }

        if (getItemCount() > 5 && holder.getIndex_position() / 5 == 1){
            binding.ivPackerFirstContentBottom.setVisibility(View.VISIBLE);
        }else if (getItemCount() <= 5){
            binding.ivPackerFirstContentBottom.setVisibility(View.VISIBLE);
        }else {
            binding.ivPackerFirstContentBottom.setVisibility(View.GONE);
        }
    }
}
